﻿using System;
using System.Linq;
using FLib;
using LibraryGuard.Interfaces;
using LibraryGuard.Interfaces.Configuration;

namespace LibraryGuard.Configuration
{
	/// <summary>
	/// For information, see <see cref="IGuardAttibute"/>.
	/// </summary>
	[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
	public sealed class GuardAttribute
		: Attribute, IGuardAttribute
	{
		#region IGuardAttribute Members
		/// <summary>
		/// Guard type.
		/// </summary>
		public Type GuardType { get; private set; }
		#endregion

		#region Constructor
		public GuardAttribute(Type guardType)
		{
			Validate.Debug(() => guardType, v => v
					.NotNull()
					.That(t =>
						t.Implements(typeof(IGuard)) &&
						t.GetConstructor(new Type[] { typeof(IConfiguration), typeof(IGuardConfiguration) }) != null)
				);
			this.GuardType = guardType;
		}
		#endregion
	}
}
